// EG4PGAction.h -- a brief definition for particle generation
// Created: Jan. 26, 2019, transcribed by Asia SUN
// Last modified: Jan. 26, 2019

#ifndef EG4PGAction_h
#define EG4PGAction_h

#include <string>
#include "G4VUserPrimaryGeneratorAction.hh"
#include "G4ThreeVector.hh"

using std::string;

class G4GeneralParticleSource;
class G4ParticleDefinition;
class G4ParticleGun;
class TRandom3;
class TH1F;

class EG4PGAction : public G4VUserPrimaryGeneratorAction{
public:
  EG4PGAction(bool usingGun);
  virtual ~EG4PGAction();

  virtual void GeneratePrimaries(G4Event *) override;
  /// read from file to fill hTheta
  virtual void SetThetaHist(const string &file);
  virtual void SetTargetZ(double z){ fTargetZ = z; }

  virtual void GPSShoot(G4Event *event); ///< shoot using fGPS
  virtual void GunShoot(G4Event *event); ///< shoot using fGun

protected:
  virtual void ConstructIon(int Z, int A);

  TRandom3 *fRdm;
  G4GeneralParticleSource *fGPS;
  G4ParticleGun *fGun;

  double fTargetZ, fTargetHDZ; ///< HDZ: half length along z (thickness) in mm
  /// particle source definition
  double fEkPerU; ///< in MeV/u
  int fZ, fA;
  G4ParticleDefinition *fParticle;
  double fT; ///< starting time of the particle source in ns
  double fPP; ///< PP = |P|, in MeV/c
  double fPhi, fTheta; ///< in rad
  double fEk; ///< in MeV
  G4ThreeVector fPos, fP; ///< in mm and MeV/c
  TH1F *hTheta; ///< histogram for user-input theta distribution

  bool fUsingGun; ///< whether using fGun
};

#endif
